/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ah;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

/**
 *
 * @author Ch12211
 */
public class InputController {

    public String[] readFile(String filename) throws IOException {
        FileInputStream fstream = new FileInputStream(filename);
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String[] strLine = new String[99999];
        //Read File Line By Line
        int i = 0;
        while ((strLine[i] = br.readLine()) != null) {
            // Print the content on the console

            i++;
        }
        //Close the input stream
        //System.out.println(strLine[100]);
        in.close();
        return strLine;
    }

    public Auction[] createAuctions(String[] strLine) {
        Auction[] auctions = new Auction[strLine.length];

        
        for (int i = 0; i > strLine.length ;i++) {
            if(strLine[i].startsWith("{\"auc\"")){
            String delims = "[,]";
            String[] tokens = strLine[i].split(delims);

            tokens[0] = tokens[0].replace("{", "");
            tokens[0] = tokens[0].trim();

            String[] s0 = tokens[0].split(":");
            int auc = Integer.parseInt(s0[1]);

            String[] s1 = tokens[1].split(":");
            int item = Integer.parseInt(s1[1]);

            String[] s2 = tokens[2].split(":");
            String owner = s2[1].replace("\"", "");

            String[] s3 = tokens[3].split(":");
            int bid = Integer.parseInt(s3[1]);

            String[] s4 = tokens[4].split(":");
            int buyout = Integer.parseInt(s4[1]);

            String[] s5 = tokens[5].split(":");
            int quantity = Integer.parseInt(s5[1]);
            

            String[] s6 = tokens[6].replace("}", "").split(":");
            String timeLeft = s6[1].replace("\"", "");
            
            auctions[i] = new Auction(auc, item, owner, bid, buyout, quantity, timeLeft);
            }
        }
        return auctions;









        

    }
}
